<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账户设置">
            <!-- 放置表单 -->
            <el-form label-width="120px" style="margin-left: 120px; margin-top:30px">
              <el-form-item label="姓名:">
                <el-input v-model="formData.username" style="width:300px" />
              </el-form-item>
              <el-form-item label="密码:">
                <el-input v-model="formData.password" style="width:300px" type="password" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="updataUserInfo">更新</el-button>
                <el-button @click="$router.back()">取消</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <el-row type="flex" justify="end">
              <el-tooltip content="打印个人基本信息">
                <router-link :to="`/employees/print/${id}?type=personal`">
                  <i class="el-icon-printer" />
                </router-link>
              </el-tooltip>
            </el-row>
            <userInfoVue />
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <el-row type="flex" justify="end">
              <el-tooltip content="打印岗位信息">
                <router-link :to="`/employees/print/${id}?type=job`">
                  <i class="el-icon-printer" />
                </router-link>
              </el-tooltip>
            </el-row>
            <jobInfo />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getDetailsInfo } from '@/api/user'
import userInfoVue from './components/user-info.vue'
import jobInfo from './components/job-info.vue'
import { saveUserDetailById } from '@/api/employees'
export default {
  components: {
    userInfoVue,
    jobInfo
  },
  data() {
    return {
      id: this.$route.params.id,
      formData: {
        username: '',
        password: ''
      }
    }
  },
  created() {
    this.id = this.$route.params.id
    this.getDetailsInfo()
  },
  methods: {
    async   getDetailsInfo() { // 获取当前员工信息
      const result = await getDetailsInfo(this.id)
      this.formData = result
    },
    async updataUserInfo() {
      try {
        await saveUserDetailById(this.formData)
        await this.getDetailsInfo()
        this.$message.success('修改成功')
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style>

</style>
